package com.ruoyi.content.controller;

import java.util.List;

import com.ruoyi.content.domain.Article;
import com.ruoyi.content.service.IArticleService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.content.domain.Station;
import com.ruoyi.content.service.IStationService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 服务站 信息操作处理
 * 
 * @author cloudoer
 * @date 2019-07-11
 */
@Controller
@RequestMapping("/content/station")
public class StationController extends BaseController
{
    private String prefix = "content/station";
	
	@Autowired
	private IStationService stationService;

	@Autowired
	private IArticleService articleService;
	
	@RequiresPermissions("content:station:view")
	@GetMapping()
	public String station()
	{
	    return prefix + "/station";
	}
	
	/**
	 * 查询服务站列表
	 */
	@RequiresPermissions("content:station:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Station station)
	{
		startPage();
        List<Station> list = stationService.selectStationList(station);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出服务站列表
	 */
	@RequiresPermissions("content:station:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Station station)
    {
    	List<Station> list = stationService.selectStationList(station);
        ExcelUtil<Station> util = new ExcelUtil<Station>(Station.class);
        return util.exportExcel(list, "station");
    }
	
	/**
	 * 新增服务站
	 */
	@GetMapping("/add")
	public String add(ModelMap mmap)
	{
		List<Article> list = articleService.selectArticleList(new Article());
		mmap.put("articles", list);
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存服务站
	 */
	@RequiresPermissions("content:station:add")
	@Log(title = "服务站", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Station station)
	{
		return toAjax(stationService.insertStation(station));
	}

	/**
	 * 修改服务站
	 */
	@GetMapping("/edit/{stationId}")
	public String edit(@PathVariable("stationId") Long stationId, ModelMap mmap)
	{
		List<Article> list = articleService.selectArticleList(new Article());
		mmap.put("articles", list);
		Station station = stationService.selectStationById(stationId);
		mmap.put("station", station);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存服务站
	 */
	@RequiresPermissions("content:station:edit")
	@Log(title = "服务站", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Station station)
	{		
		return toAjax(stationService.updateStation(station));
	}
	
	/**
	 * 删除服务站
	 */
	@RequiresPermissions("content:station:remove")
	@Log(title = "服务站", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(stationService.deleteStationByIds(ids));
	}
	
}
